package com.dragonsoftbravo.sqlbuilder.sql.where;

import java.util.Arrays;

import com.dragonsoftbravo.sqlbuilder.sql.Builder;
import com.dragonsoftbravo.sqlbuilder.sql.where.builder.Comp;
import com.dragonsoftbravo.sqlbuilder.sql.where.builder.Condition;

public abstract class BuildWhere<T extends Builder> extends Builder implements Where<T> {

	public BuildWhere(StringBuilder sqlBuilder) {
		super(sqlBuilder);
	}
	
	@Override
	public void buildWhere(String... args) {
		buildWhere(Arrays.asList(args));
	}

	@Override
	public void buildWhere(Iterable<String> args) {
		if(args!=null&&args.iterator().hasNext()) {
			sqlBuilder.append(" WHERE");
			for (String s : args) {
				sqlBuilder.append(" ").append(s).append(" AND");
			}
			sqlBuilder.delete(sqlBuilder.length() - 4, sqlBuilder.length());
		}
	}

	@Override
	public T where(Condition builder) {
		return where(builder.build());
	}
	public T where(Comp builder) {
		return where(builder.build());
	}
}
